package training.collections;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class ListDemo {

	
	public List<String> listDemoWithGenericVersion(){
		
		List<String> namesList = new ArrayList<String>();
		namesList.add("Name1");
		namesList.add("Name2");
		namesList.add("Name3");
		
		System.out.println(namesList);
		System.out.println(namesList.size());
		
		List<String> namesList1 = new ArrayList<String>();
		namesList1.add("Name1a");
		namesList1.add("Name2a");
		namesList1.add("Name3a");
		
		
		namesList.addAll(namesList1);
		
		System.out.println(namesList);
		System.out.println(namesList.size());
		
		namesList.remove(1);
		namesList.remove("Name2a");
		
		
		System.out.println(namesList);
		System.out.println(namesList.size());
		return namesList;
		
		
		//namesList.add(1);
		
	}
	public void listDemoForIterator(List<String> input){
		
		Iterator<String> ir = input.iterator();
		while(ir.hasNext()){
			String name =ir.next();
			System.out.println(name);
			//input.remove(name); //this is wrong way of doing it.
			ir.remove();
		}
		
	}
	public static void main(String[] args) {
		
		ListDemo demo = new ListDemo();
		List<String> namesList =demo.listDemoWithGenericVersion();
		demo.listDemoForIterator(namesList);
		
		//to get synchronized list.
		List<String> synchronizedList = Collections.synchronizedList(namesList);
	
		

	}

}
